package string;

public class test {
    public static void main(String[] args) {
        String s1 = getHostName("www.tedu.cn");
        String s2 = getHostName("http://www.tarena.com");
        String s3 = getHostName("doc.canglaoshi.com.cn");
        System.out.println("s1:"+s1);//s1:tedu
        System.out.println("s2:"+s2);//s2:tarena
        System.out.println("s3:"+s3);//s3:canglaoshi
    }
    public static String getHostName(String address){//截取域名
        int x = address.indexOf(".")+1;
        int y = address.indexOf(".",x);
        return address.substring(x,y);
    }
}
